package easy;

import java.util.ArrayList;
import java.util.List;

public class Solution_1560 {

    public List<Integer> mostVisited(int n, int[] rounds) {
        int max = 0;
        int[] counts = new int[n + 1];
        rounds[0]--;
        for (int i = 0; i < rounds.length - 1; i++) {
            int r = rounds[i + 1] > rounds[i] ? rounds[i + 1] : rounds[i + 1] + n;
            for (int j = rounds[i]+1; j <= r; j++) {
                int k = j % n;
                counts[k]++;
                max = Math.max(max, counts[k]);
            }
        }
        counts[n] = counts[0];
        List<Integer> list = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            if (counts[i] == max) {
                list.add(i);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        Solution_1560 model = new Solution_1560();
        System.out.println(model.mostVisited(4, new int[]{1, 3, 1, 2}));
        System.out.println(model.mostVisited(2, new int[]{2, 1, 2, 1, 2, 1, 2, 1, 2}));
        System.out.println(model.mostVisited(7, new int[]{1, 3, 5, 7}));
    }
}
